package com.bjpowernode.springevent.controller;

import cn.hutool.core.date.DateUtil;
import com.bjpowernode.springevent.events.NoticeEvent;
import jakarta.annotation.Resource;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@ResponseBody
public class NoticeEventController {
    @Resource
    ApplicationEventPublisher applicationEventPublisher;
    @RequestMapping("/test")
    public String test(String msg){
        System.out.println(DateUtil.now()+"--->事件源触发了事件开始");
        //触发事件
        NoticeEvent noticeEvent= new NoticeEvent(this,msg);
        applicationEventPublisher.publishEvent(noticeEvent);
        System.out.println(DateUtil.now()+"--->事件源触发事件之后");
        return "ok";
    }
}
